package com.busdepot.webbapp.domain;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.busdepot.webapp.domain.BusDepotPart;
import com.busdepot.webapp.domain.ImcPart;
import com.busdepot.webapp.domain.PartService;
import com.busdepot.webapp.domain.ShippingService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "/spring-service.xml" })
public class ShippingServiceTestIntegration {
	
	private Logger logger = Logger.getLogger(ShippingServiceTestIntegration.class);
	
	@Autowired
	private ApplicationContext applicationContext;
	
	@Autowired
	private ShippingService shippingService;
	
	@Autowired
	private PartService partService;
	
	@Test
	public void getCod(){
		Double cod = shippingService.getCodCharge();
		logger.debug("COD charge: $" + cod);
	}
	
	@Test
	public void getHandling(){
		Double handling = shippingService.getHandlingCharge();
		logger.debug("Handling charge: $" + handling);
	}
	
	
	@Test
	public void getShippingRate(){
		int shippingRegion = 6;
		int shippingType = 1;
		double rate = shippingService.getShippingRate(shippingRegion, shippingType);
		logger.debug("Shipping rate: " + rate);
	}
	
	@Test
	public void getShippingRegion(){
		int zip = 19518;
		int region = shippingService.getShippingRegion(zip);
		logger.debug("Region: #" + region);
	}
	
	@Test
	public void getShippingTotal(){
		double merchandiseTotal = 100; 
		double shippingRate = 0.05;
		double surchargeTotal = 5;
		double handlingCharge = 5;
		double CodCharge = 5;
		// $120 expected for return value
		double shippingTotal = shippingService.getShippingTotal(merchandiseTotal, shippingRate, surchargeTotal, handlingCharge, CodCharge);
		if (logger.isDebugEnabled()){
			logger.debug("Shipping total is: $" + shippingTotal + " // ($120 expected)");
		}	
	}
	
	@Test
	public void getSurchargeTotal(){
		BusDepotPart BdPart1 = new BusDepotPart();
		BusDepotPart BdPart2 = new BusDepotPart();
		BusDepotPart BdPart3 = new BusDepotPart();
		BdPart1.setId(283405);
		BdPart2.setId(283404);
		BdPart3.setId(283403);
		BdPart1.setVendorId(1);
		BdPart2.setVendorId(1);
		BdPart3.setVendorId(1);
		List<BusDepotPart> partList = new ArrayList();
		partList.add(BdPart1);
		partList.add(BdPart2);
		partList.add(BdPart3);
		double BdPartsSurcharge = shippingService.getSurchargeTotal(partList);
		ImcPart imcPart = new ImcPart();
		imcPart.setVendorId(1);
		double imcSurcharge = shippingService.getSurchargeForPart(imcPart);
		double surchargeTotal = BdPartsSurcharge + imcSurcharge;
		// $6 surcharge total expected
		if (logger.isDebugEnabled()){
			logger.debug("Surcharge total is: $" + surchargeTotal + " -- ($6 expected)");
		}
	}

}
